package com.itheima.service.impl;

import com.itheima.domain.Info;
import com.itheima.domain.Patient;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public void addOne(String name, String gender, String office) {
        int id =userMapper.findOneByOffice(office);
        Patient patient = new Patient();
        patient.setName(name);
        patient.setGender(gender);
        patient.setDid(id);
        userMapper.addOne(patient);
    }

    @Override
    public Info selectGenderAndOffice() {
        List<Integer> gender = userMapper.selectGender();
        List<String> name = userMapper.selectOfficeName();
        Info info = new Info();

        info.setGender(gender);
        info.setOfficeName(name);
        return info;
    }

    @Override
    public List<Patient> selectAll() {
       List<Patient> patientList =  userMapper.selectAll();
        for (Patient patient : patientList) {
            if (patient.getGender()!=null&&patient.getGender().length()>0){
                if (patient.getGender().equals("1")){
                    patient.setGender("男");
                }else {
                    patient.setGender("女");
                }
            }

            String name = userMapper.selectOne(patient.getDid());
            patient.setOffice(name);
        }
        return patientList;
    }
}
